package com.addzero.web.ui.hooks.tree

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.addzero.Route

@Composable
@Route(homePageFlag = true)
fun TreeSelectEnhancedExample() {
    // 创建示例数据，使用预定义的节点类型
    val treeData = getMockkTree()

    // 创建UseListTree实例
    val useListTree = remember {
        UseListTree<TreeNode<String>>(
            initialNodes = treeData,
            getIdFun = { it.id },
            getChildren = { it.children },
            getLaebel = { it.label },
            getNodeTypeFun = { it.type }
        ).apply {
            // 自定义节点渲染
            useTreeNodeItem.customRender = { node ->
                val nodeType = node.type
                val label = node.label
                
                // 使用默认渲染器渲染节点
                defaultTreeNodeRender(
                    node = node,
                    getType = { nodeType },
                    getLabel = { label }
                )
            }
            
            // 确保根节点默认展开
            useTreeNodeItem.expanded = true
        }
    }

    Surface(modifier = Modifier.padding(16.dp)) {
        Column(modifier = Modifier.fillMaxWidth()) {
            Text(
                text = "增强型树形选择示例",
                fontWeight = FontWeight.Bold,
                modifier = Modifier.padding(bottom = 16.dp)
            )
            
            // 渲染树形结构
            useListTree.render {}
        }
    }
}

